home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 15 code / 3D Interface / Demo3D / UDemo3D.cp < prev    next >
Encoding:
Text File  |  1994-10-21  |  10.0 KB  |  329 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. //    File:        Demo3D.cp
  3. //
  4. //    Contains:    3D drawing demo program
  5. //
  6. //    Written by:    Jamie Osborne
  7. //                 Adapted for 3.1.1 by Jeroen Schalk
  8. //
  9. //    Copyright:    © 1992-1994 by Apple Computer, Inc.
  10. //----------------------------------------------------------------------------------------
  11.  
  12. #include "UDemo3D.h"
  13.  
  14. #ifndef __TOOLUTILS__
  15. #include <ToolUtils.h>
  16. #endif
  17.  
  18. #ifndef __UFAILURE__
  19. #include <UFailure.h>
  20. #endif
  21.  
  22. #ifndef __UVIEWSERVER__
  23. #include <UViewServer.h>
  24. #endif
  25.  
  26. #ifndef __UMACAPPUTILITIES__
  27. #include <UMacAppUtilities.h>
  28. #endif
  29.  
  30. #ifndef __MENUS__
  31. #include <Menus.h>
  32. #endif
  33.  
  34. #ifndef __UWINDOW__
  35. #include <UWindow.h>
  36. #endif
  37.  
  38. #ifndef __RESOURCES__
  39. #include <Resources.h>
  40. #endif
  41.  
  42. #ifndef __STDLIB__
  43. #include <StdLib.h>
  44. #endif
  45.  
  46. #ifndef __UCONTROL__
  47. #include <UControl.h>
  48. #endif
  49.  
  50. #ifndef __U3DDRAWING__
  51. #include "U3DDrawing.h"
  52. #endif
  53.  
  54. //----------------------------------------------------------------------------------------
  55. // Constants
  56. const short c3DDrawingWind = 1001;
  57. const short c3DDrawingProcWind = 1002;
  58.  
  59. const short kModalDialog = 1010;
  60. const short kBadWindow = 1011;
  61.  
  62. const short kStrings     = 2000;
  63.  
  64. //========================================================================================
  65. // CLASS TTestApplication
  66. //========================================================================================
  67.  
  68. //----------------------------------------------------------------------------------------
  69. // TTestApplication::ITestApplication:
  70. //----------------------------------------------------------------------------------------
  71. #pragma segment AInit
  72.  
  73. #undef Inherited
  74. #define Inherited TApplication
  75. DefineClass(TTestApplication, TApplication);
  76.  
  77. void TTestApplication::ITestApplication()
  78. {
  79.     this->IApplication(kFileType, kSignature);
  80.  
  81.     macroDontDeadStrip(TDemoWindow);
  82.  
  83.     fLaunchWithNewDocument = false;        // Suppress the creation of a new document at launch
  84.  
  85.     this->DoMenuCommand(c3DDrawingWind);        // Show the View window
  86.  
  87. } // TTestApplication::ITestApplication
  88.  
  89. //----------------------------------------------------------------------------------------
  90. // TTestApplication::DoMakeDocument:
  91. //----------------------------------------------------------------------------------------
  92. #pragma segment AOpen
  93.  
  94. TDocument* TTestApplication::DoMakeDocument(CommandNumber    /*itsCommandNumber*/,
  95.                                            TFile*           /*itsFile*/ )// override
  96. {
  97.     return NULL;
  98. } // TTestApplication::DoMakeDocument
  99.  
  100. //----------------------------------------------------------------------------------------
  101. // TTestApplication::DoMenuCommand:
  102. //----------------------------------------------------------------------------------------
  103. #pragma segment ASelCommand
  104.  
  105. void TTestApplication::DoMenuCommand(CommandNumber aCommandNumber)// override
  106. {
  107.     switch (aCommandNumber)
  108.     {
  109.     case c3DDrawingWind:
  110.         this->MakeDrawingWind();
  111.         break;
  112.     case c3DDrawingProcWind:
  113.         this->MakeDrawingProcWind();
  114.         break;
  115.     default:
  116.         Inherited::DoMenuCommand(aCommandNumber);
  117.         break;
  118.     }
  119. } // TTestApplication::DoMenuCommand
  120.  
  121. //----------------------------------------------------------------------------------------
  122. // TTestApplication::DoSetupMenus:
  123. //----------------------------------------------------------------------------------------
  124. #pragma segment ARes
  125.  
  126. void TTestApplication::DoSetupMenus()// override
  127. {
  128.     Inherited::DoSetupMenus();
  129.  
  130.     Enable(c3DDrawingWind, true);
  131.     Enable(c3DDrawingProcWind, true);
  132.  
  133. } // TTestApplication::DoSetupMenus
  134.  
  135. //----------------------------------------------------------------------------------------
  136. // TTestApplication::MakeDrawingWind:
  137. //----------------------------------------------------------------------------------------
  138. #pragma segment ARes
  139.  
  140. void TTestApplication::MakeDrawingWind()
  141. {
  142.     TWindow *        aWindow = gViewServer->NewTemplateWindow(c3DDrawingWind, NULL);
  143.     FailNIL(aWindow);
  144.     aWindow->Open();
  145.     
  146. } // TTestApplication::MakeTemplateViews
  147.  
  148. //----------------------------------------------------------------------------------------
  149. // TTestApplication::MakeDrawingProcWind:
  150. //----------------------------------------------------------------------------------------
  151. #pragma segment ASelCommand
  152.  
  153. void TTestApplication::MakeDrawingProcWind()
  154. {
  155.     TWindow *aWindow;
  156.     VPoint    itsLocation, itsSize;
  157.  
  158.     FailNIL(aWindow = gViewServer->NewTemplateWindow(c3DDrawingProcWind, NULL));
  159.  
  160.     TStaticText *aStaticText = new TStaticText;
  161.     itsLocation = VPoint(15, 13);
  162.     itsSize = VPoint(362, 16);
  163.     aStaticText->IStaticText(aWindow, itsLocation, itsSize, sizeVariable, sizeVariable, kStrings, 1);
  164.  
  165.     TStaticText *aStaticText2 = new TStaticText;
  166.     itsLocation = VPoint(278, 188);
  167.     itsSize = VPoint(188, 48);
  168.     aStaticText2->IStaticText(aWindow, itsLocation, itsSize, sizeVariable, sizeVariable, kStrings, 2);
  169.  
  170.     TStaticText *aStaticText3 = new TStaticText;
  171.     itsLocation = VPoint(269, 53);
  172.     itsSize = VPoint(116, 16);
  173.     aStaticText3->IStaticText(aWindow, itsLocation, itsSize, sizeVariable, sizeVariable, kStrings, 3);
  174.  
  175.     TCluster *aCluster = new TCluster;
  176.     itsLocation = VPoint(266, 120);
  177.     itsSize = VPoint(199, 53);
  178.     aCluster->ICluster(aWindow, itsLocation, itsSize, sizeVariable, sizeVariable, kNoResource, 0);
  179.     aCluster->SetLabel("A Cluster!", kRedraw);
  180.  
  181.     itsSize = VPoint(78, 18);
  182.     T3DRadio *aRadio1 = new T3DRadio;
  183.     itsLocation = VPoint(10, 13);
  184.     aRadio1->I3DRadio(aCluster, itsLocation, itsSize, sizeVariable, sizeVariable, "Radio 1", true);
  185.  
  186.     T3DRadio *aRadio2 = new T3DRadio;
  187.     itsLocation = VPoint(10, 31);
  188.     aRadio2->I3DRadio(aCluster, itsLocation, itsSize, sizeVariable, sizeVariable, "Radio 2" , false);
  189.  
  190.     T3DRadio *aRadio3 = new T3DRadio;
  191.     itsLocation = VPoint(107, 13);
  192.     aRadio3->I3DRadio(aCluster, itsLocation, itsSize, sizeVariable, sizeVariable, "Disabled", false);
  193.  
  194.     T3DRadio *aRadio4 = new T3DRadio;
  195.     itsLocation = VPoint(107, 31);
  196.     aRadio4->I3DRadio(aCluster, itsLocation, itsSize, sizeVariable, sizeVariable, "Disabled", false);
  197.     aRadio4->DimState(true, false);
  198.     aRadio4->SetEnable(false);
  199.  
  200.     T3DCheckBox *aCheckBox = new T3DCheckBox;
  201.     itsLocation = VPoint(26, 203);
  202.     itsSize = VPoint(154, 18);
  203.     aCheckBox->I3DCheckBox(aWindow, itsLocation, itsSize, sizeVariable, sizeVariable, "Enabled Check Box", false);
  204.  
  205.     T3DCheckBox *aCheckBox2 = new T3DCheckBox;
  206.     itsLocation = VPoint(26, 218);
  207.     itsSize = VPoint(154, 28);
  208.     aCheckBox2->I3DCheckBox(aWindow, itsLocation, itsSize, sizeVariable, sizeVariable, "Disabled Check Box", false);
  209.     aCheckBox2->DimState(true, false);
  210.     aCheckBox2->SetEnable(false);
  211.  
  212.     T3DButton *aButton = new T3DButton;
  213.     itsLocation = VPoint(374, 244);
  214.     itsSize = VPoint(82, 20);
  215.     aButton->I3DButton(aWindow, itsLocation, itsSize, sizeVariable, sizeVariable, "Show Me");
  216.     aButton->fIdentifier = 'BDBn';
  217.     aButton->SetHilitedTextColor(CRGBColor(65535, 9109, 2210));
  218.  
  219.     T3DButton *aButton2 = new T3DButton;
  220.     itsLocation = VPoint(280, 244);
  221.     itsSize = VPoint(82, 20);
  222.     aButton2->I3DButton(aWindow, itsLocation, itsSize, sizeVariable, sizeVariable, "Disabled");
  223.     aButton2->DimState(true, false);
  224.     aButton2->SetEnable(false);
  225.  
  226.     T3DIconButton *anIcon = new T3DIconButton;
  227.     itsLocation = VPoint(36, 76);
  228.     itsSize = VPoint(26, 26);
  229.     anIcon->I3DIconButton(aWindow,itsLocation, itsSize, sizeFixed, sizeFixed, 16, 1002, kButtonMode, false);
  230.     anIcon->fIdentifier = 'IBn1';
  231.  
  232.     T3DIconButton *anIcon2 = new T3DIconButton;
  233.     itsLocation = VPoint(36, 121);
  234.     itsSize = VPoint(26, 26);
  235.     anIcon2->I3DIconButton(aWindow,itsLocation, itsSize, sizeFixed, sizeFixed, 16, 1002, kButtonMode, false);
  236.     anIcon2->DimState(true, false);
  237.     anIcon2->SetEnable(false);
  238.  
  239.     TView *aView = new TView;
  240.     itsLocation = VPoint(246, 54);
  241.     itsSize = VPoint(2, 210);
  242.     aView->IView(NULL,aWindow,itsLocation, itsSize, sizeFixed, sizeFixed);
  243.  
  244.     T3DLineLeftAdorner *aLineAdorner = new T3DLineLeftAdorner;
  245.     aLineAdorner->I3DLineLeftAdorner(true);
  246.     aView->AddAdorner(aLineAdorner, kAdornLast, true);
  247.  
  248.     TEditText *anEditText = new TEditText;
  249.     itsLocation = VPoint(269, 69);
  250.     itsSize = VPoint(199, 22);
  251.     anEditText->IEditText(aWindow, itsLocation, itsSize, 255);
  252.     anEditText->SetText("Edit Text", kDontRedraw);
  253.     anEditText->DeleteAdornerByID(kFrameAdorner, true);        // We make our own frame
  254.  
  255.     TWhiteBackgroundAdorner    *back = new TWhiteBackgroundAdorner;
  256.     back->IWhiteBackgroundAdorner(true);
  257.  
  258.     T3DFrameAdorner    *frame = new T3DFrameAdorner;
  259.     frame->I3DFrameAdorner(true);
  260.  
  261.     anEditText->AddAdorner(back, kAdornFirst, true);
  262.     anEditText->AddAdorner(frame, kAdornLast, true);
  263.  
  264.     TControl *aControl = new TControl;
  265.     itsLocation = VPoint(93, 68);
  266.     itsSize = VPoint(134, 90);
  267.     aControl->IControl(aWindow,itsLocation, itsSize, sizeFixed, sizeFixed);
  268.  
  269.     TWhiteBackgroundAdorner    *back2 = new TWhiteBackgroundAdorner;
  270.     back2->IWhiteBackgroundAdorner(true);
  271.  
  272.     T3DFrameAdorner    *frame2 = new T3DFrameAdorner;
  273.     frame2->I3DFrameAdorner(true);
  274.     aControl->AddAdorner(back2, kAdornFirst, true);
  275.     aControl->AddAdorner(frame2, kAdornLast, true);
  276.  
  277.     TextStyle style;
  278.     GetPortTextStyle(style);
  279.     itsLocation = VPoint(2,2);
  280.     itsSize = VPoint(115, 86);
  281.     TScroller *scroller = new TScroller;
  282.     scroller->IScroller(aControl, itsLocation, itsSize, sizeRelSuperView, sizeRelSuperView,
  283.                                 VPoint(86, 86), false, true);
  284.  
  285.     TTextListView *aTextListView = new TTextListView;
  286.     aTextListView->ITextListView(NULL, scroller, itsLocation, itsSize, sizeSuperView,
  287.                                          sizeSuperView, 2, 16, 0, false, false, 2, 2, true, style);
  288.  
  289.  
  290.     aWindow->Open();
  291.     
  292. } // TTestApplication::MakeProcedureViews
  293.  
  294. //----------------------------------------------------------------------------------------
  295.  
  296. #undef Inherited
  297. #define Inherited TWindow
  298. DefineClass(TDemoWindow, TWindow);
  299.  
  300. void TDemoWindow::DoEvent(EventNumber eventNumber,
  301.                          TEventHandler* source,
  302.                          TEvent* event)
  303. {
  304.     switch(eventNumber)
  305.     {
  306.     case mButtonHit:
  307.         if (source == this->FindSubView('BDBn'))
  308.         {
  309.             TWindow *aWindow;
  310.             FailNIL(aWindow = gViewServer->NewTemplateWindow(kBadWindow, NULL));
  311.             aWindow->Open();
  312.         }
  313.         break;
  314.     case mIconButtonHit:
  315.         if (source == this->FindSubView('IBn1'))
  316.         {
  317.             TWindow *aWindow;
  318.             FailNIL(aWindow = gViewServer->NewTemplateWindow(kModalDialog, NULL));
  319.             IDType dismisser = aWindow->PoseModally();
  320.             if (dismisser == 'ok  ')
  321.                 aWindow->CloseAndFree();
  322.         }
  323.         break;
  324.     default:
  325.         Inherited::DoEvent(eventNumber, source, event);
  326.         break;
  327.     }
  328. }
  329.